<template>
<div>
  <el-form>
    <el-form-item  label="商品名称" prop="name">
      <el-input  label-width="200px" v-model="commodity.commodityName"></el-input>
    </el-form-item>
    <el-form-item label="商品价格" >
      <el-input v-model="commodity.price" placeholder="XX元"></el-input>
    </el-form-item>
   <el-form-item label="商品产地">
      <el-input v-model="commodity.orgin"></el-input>
    </el-form-item>
     <el-form-item label="商品包装" >
      <el-input v-model="commodity.package" placeholder="箱、盒、袋"></el-input>
    </el-form-item>
      <el-form-item label="数量" >
      <el-input v-model="commodity.amount" placeholder="20/箱"></el-input>
    </el-form-item>
      <el-form-item label="库存">
      <el-input v-model="commodity.inventoryNumbers"></el-input>
    </el-form-item>
    <!-- 图片上传 -->
    <el-upload action="/students/uploadImage" list-type="picture-card" >
      <i class="el-icon-plus"></i>
    </el-upload>
    <!-- 图片上传 -->
    <el-form-item>
      <el-button type="primary" @click="submitForm(commodity)">提交</el-button>
    </el-form-item>
  </el-form>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
let { mapActions, mapState } = createNamespacedHelpers("commodity");
export default {
  data() {
    return {
      commodity: {
        commodityName: "",
        price: "",
        orgin: "",
        package: "",
        amount:'',
        inventoryNumbers:"",
        image: "",
      },
    };
  },
  methods: {
    ...mapActions(['addcommodity']),
    async submitForm(data) {
      const a = await this.addcommodity(data);
      if (a._id) {
        this.open2();
        this.$router.push("/admin/index/commoditylist");
      }
    },
    open2() {
      this.$message({
        message: "恭喜你,添加成功",
        type: "success"
      });
    }
  }
};
</script>

<style scoped>
.pagination .paginationMain {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
.pagination .paginationMain span {
  display: block;
  width: 50px;
  height: 30px;
  border: 1px solid #999;
  line-height: 30px;
  text-align: center;
  margin-right: 10px;
  font-size: 14px;
  border-radius: 5px;
  cursor: pointer;
}
.pagination .paginationMain span:hover {
  border: 1px solid #f3a83f;
  color: #f3a83f;
}
div{
    width: 300px;
    margin: 0px auto;
    text-align: center;
}
.cell {
  text-align: center;
}
.el-main[data-v-452a4712]{
  text-align: center;
}
</style>